<?php


namespace app\admin\controller;

use think\Db;
use think\Exception;

class User
{

        public function add_user(){
            $db=new Db();
            $username=$_POST['username'];
            $password=$_POST['password'];
            $name=$_POST['name'];
            $styleMessage=$_POST['styleMessage'];
            $arr=array("username"=>$username,"password"=>$password,"name"=>$name,"styleMessage"=>$styleMessage);
            $effect_row=$db::table("user")->insert($arr);
            if($effect_row == 1){
                $arr=array("state"=>200);
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            }else{
                $arr=array("state"=>400);
                echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            }
        }

        public function select_user(){
            $db=new Db();
            $res=$db::table("user")->select();
            echo json_encode($res,JSON_UNESCAPED_UNICODE);
        }

        public function select_user_by_username(){
            $db=new Db();
            $username=$_POST['username'];
            $res=$db::table('user')->where('username',$username)->find();
            echo json_encode($res,JSON_UNESCAPED_UNICODE);
        }
}